{
	UCE - cross-platform game engine written in delphi.
	Copyright (c) 2009, Shutko Vitaly

	This file is part of UCE.

	UCE is free software; you can redistribute it and/or
	modify it under the terms of the GNU Lesser General Public
	License as published by the Free Software Foundation; either
	version 2.1 of the License, or (at your option) any later version.

	UCE is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
	Lesser General Public License for more details.

	You should have received a copy of the GNU Lesser General Public
	License along with this library; if not, write to the Free Software
	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
}

unit uCol;

interface

uses
  uSpr;

type
  TCol = class
    function PointRect(x, y, rx, ry, rw, rh: Single): Boolean;
    function PointSprite(x, y: Single; spr: TSpr): Boolean;
    function PointCircle(x, y: Single; cx, cy, cr: Single): Boolean;
    function CircleCircle(x, y, r, x2, y2, r2: Single): Boolean;
  end;

implementation

uses
  uTyp, uMat;

function TCol.PointRect(x, y, rx, ry, rw, rh: Single): Boolean;
begin
  Result := (x > rx) and (x < rx + rw) and (y > ry) and (y < ry + rh);
end;

function TCol.PointSprite(x, y: Single; spr: TSpr): Boolean;
begin
  Result := PointRect(x, y, spr.x, spr.y, spr.w, spr.h);
end;

function TCol.PointCircle(x, y: Single; cx, cy, cr: Single): Boolean;
begin
  Result := MakeVec(cx - x, cy - y).Len < cr;
end;

function TCol.CircleCircle(x, y, r, x2, y2, r2: Single): Boolean;
begin
  Result := MakeVec(x2 - x, y2 - y).Len < r + r2;
end;

end.